﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess;
namespace SQT.tracnghiem.Ajax.ASP.Notification
{
    public partial class notification_count : System.Web.UI.Page
    {
        public int count = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            var unseen = new TblNotificationController().FetchAll().Where(x => x.NotificationIsDelete == false && !String.IsNullOrEmpty(x.NotificationReceiver));
            string adminID = Session["admin_id"].ToString();
            
            foreach (TblNotification noti in unseen)
            {
                string[] receivers = noti.NotificationReceiver.Split(',');
                foreach (string receiver in receivers)
                {
                    if (receiver == adminID)
                    {
                        count++;
                        string[] get_seen = noti.NotificationSeen.Split(',');
                        foreach (string seen in get_seen)
                        {
                            if (seen == adminID)
                            {
                                count--;
                                break;
                            }
                        }
                        break;
                    }
                }
            }
        }
    }
}